Skip to content
A lightweight library to simplify and generalize the process of writing unit tests for C applications.
Shell C Makefile M4
Branch: master
Clone or download
mbrukman Merge pull request #59 from mbrukman/readme-split
Split detailed user guide from README to new file
Latest commit 1a65517 Apr 16, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs Split detailed user guide from README to new file Mar 13, 2019
m4 Cleaned up directory tree after import from code.google.com. Dec 8, 2015
packages Cleaned up directory tree after import from code.google.com. Dec 8, 2015
src Fix grammar in README and code samples [skip ci] Mar 3, 2019
windows Cleaned up directory tree after import from code.google.com. Dec 8, 2015
.travis.yml Add basic Travis CI config. Jan 30, 2019
AUTHORS Cleaned up directory tree after import from code.google.com. Dec 8, 2015
ChangeLog Cleaned up directory tree after import from code.google.com. Dec 8, 2015
INSTALL Cleaned up directory tree after import from code.google.com. Dec 8, 2015
LICENSE.txt Fix Apache license text to be Apache 2.0 verbatim Jan 20, 2019
Makefile.am Fix build: remove references to doc/index.html Mar 5, 2019
Makefile.in Fix build: remove references to doc/index.html Mar 5, 2019
NEWS Cleaned up directory tree after import from code.google.com. Dec 8, 2015
README.md Split detailed user guide from README to new file Mar 13, 2019
aclocal.m4 Cleaned up directory tree after import from code.google.com. Dec 8, 2015
autogen.sh Cleaned up directory tree after import from code.google.com. Dec 8, 2015
compile Cleaned up directory tree after import from code.google.com. Dec 8, 2015
config.guess Cleaned up directory tree after import from code.google.com. Dec 8, 2015
config.sub Cleaned up directory tree after import from code.google.com. Dec 8, 2015
configure Update README to README.md in the build files Jan 27, 2019
configure.ac Update README to README.md in the build files Jan 27, 2019
depcomp Cleaned up directory tree after import from code.google.com. Dec 8, 2015
install-sh Cleaned up directory tree after import from code.google.com. Dec 8, 2015
ltmain.sh Clean ltmain.sh Nov 18, 2017
missing Cleaned up directory tree after import from code.google.com. Dec 8, 2015
mkinstalldirs Cleaned up directory tree after import from code.google.com. Dec 8, 2015

README.md

Cmockery Unit Testing Framework

Build Status

Contents

Cmockery is a lightweight library that is used to author C unit tests.

Overview

Cmockery tests are compiled into stand-alone executables and linked with the Cmockery library, the standard C library, and the module being tested. Any symbols external to the module being tested should be mocked - replaced with functions that return values determined by the test - within the test application. Even though significant differences may exist between the target execution environment of a code module and the environment used to test the code, the unit testing is still valid since its goal is to test the logic of a code modules at a functional level and not necessarily all of its interactions with the target execution environment.

It may not be possible to compile a module into a test application without some modification; therefore, the preprocessor symbol UNIT_TESTING should be defined when Cmockery unit test applications are compiled so code within the module can be conditionally compiled for tests.

More detailed information about the mechanics of writing tests with Cmockery can be found in docs/user_guide.md.

Building

To compile the Cmockery library and example applications on Linux, run:

$ ./configure
$ make

To compile on Windows, run:

> vsvars.bat
> cd windows
> nmake

This code has been tested on Linux (Ubuntu) and Windows using VC++7 and VC++8.

Motivation

There are a variety of C unit testing frameworks available; however, many of them are fairly complex and require the latest compiler technology. Some development requires the use of old compilers which makes it difficult to use some unit testing frameworks. In addition, many unit testing frameworks assume the code being tested is an application or module that is targeted to the same platform that will ultimately execute the test. Because of this assumption, many frameworks require the inclusion of standard C library headers in the code module being tested, which may collide with the custom or incomplete implementation of the C library utilized by the code under test.

Cmockery only requires a test application is linked with the standard C library which minimizes conflicts with standard C library headers. Also, Cmockery tries avoid the use of some of the newer features of C compilers.

This results in Cmockery being a relatively small library that can be used to test a variety of exotic code. If a developer wishes to simply test an application with the latest compiler, then other unit testing frameworks may be preferable.

Community

If you have questions about Cmockery, use the following resources:

  • Stack Overflow: use the cmockery tag

  • Mailing list: cmockery (at) googlegroups.com (archives)

    To join with a Google account, use the web UI; to subscribe/unsubscribe with an arbitrary email address, send an email to:

    • cmockery+subscribe (at) googlegroups.com
    • cmockery+unsubscribe (at) googlegroups.com

License

Cmockery is licensed under the Apache 2.0 license; please see LICENSE.txt for details.

You can’t perform that action at this time.